<template></template>

<script>
import model_pipes from "./model_pipes.json";
import model_junction from "./model_junction.json";
import model_valves from "./model_valves.json";
import model_reservoirs from "./model_reservoirs.json";

// let g = {
//   A: ["B", "C", "D"],
//   B: ["A", "E", "F"],
//   C: ["A", "G", "D"],
//   D: ["A", "C", "G", "H"],
//   E: ["B", "I"],
//   F: ["B"],
//   G: ["C", "D"],
//   H: ["D"],
//   I: ["E"],
// };

let g = {};

model_junction.forEach((item) => {
  g[item.CODE] = [];
});

model_reservoirs.forEach((item) => {
  g[item.CODE] = [];
});

model_pipes.forEach((item) => {
  g[item.STARTNODE].push(item.ENDNODE);
  g[item.ENDNODE].push(item.STARTNODE);
});

model_valves.forEach((item) => {
  g[item.STARTNODE].push(item.ENDNODE);
  g[item.ENDNODE].push(item.STARTNODE);
});

function dfs(g, sNode, nNode, eNode, d, visited, allPath) {
  if (visited[nNode] === true) {
    return;
  }
  for (let i = 0; i <= g[nNode].length - 1; i++) {
    if (g[nNode][i] === eNode) {
      d[nNode] = g[nNode][i];
      let temp = d[sNode];
      let path = [];
      path.push(sNode);
      while (temp != eNode) {
        path.push(temp);
        temp = d[temp];
      }
      path.push(temp);
      allPath.push(path);
      console.log(allPath);
      return;
    } else {
      d[nNode] = g[nNode][i];
      visited[nNode] = true;
      dfs(g, sNode, g[nNode][i], eNode, d, visited, allPath);
      visited[nNode] = false;
    }
  }
  return allPath;
}

// console.log("g:", g);

dfs(g, "CPP_FE00211", "CPP_FE00211", "Up_V58000", {}, {}, []);
</script>
